package com.carepad.dao;

import com.carepad.entity.ClientBasic;
import com.carepad.entity.ClientBasicExample;
import com.carepad.entity.mapper.SelectClient;

import java.util.List;

import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.ResultMap;
import org.apache.ibatis.annotations.Select;

public interface ClientBasicMapper {

	int countByExample(ClientBasicExample example);

	int deleteByExample(ClientBasicExample example);

	int deleteByPrimaryKey(Integer uid);

	int insert(ClientBasic record);
	
	int insertSelective(ClientBasic record);

	List<ClientBasic> selectByExample(ClientBasicExample example);

	ClientBasic selectByPrimaryKey(Integer uid);

	int updateByExampleSelective(@Param("record") ClientBasic record,@Param("example") ClientBasicExample example);

	int updateByExample(@Param("record") ClientBasic record,@Param("example") ClientBasicExample example);

	int updateByPrimaryKeySelective(ClientBasic record);

	
	@Select("SELECT  tcb.UID, tcb.CLIENTNAME, tas.ADDRESS1, tas.HCS_ID, tas.CLIENT_ID "
			+ "FROM (tbl_assessment_sheets  tas join tbl_client_basic tcb)"
			+ "WHERE (tas.CLIENT_ID = tcb.UID) AND tas.CURRENT_USE = 1 GROUP BY tas.CLIENT_ID")
	@ResultMap(value = "SelectUserResultMap")
	List<SelectClient> findClientBasicUserSummaryList();
	
	
	@Select("SELECT  tcb.UID, tcb.CLIENTNAME, tas.ADDRESS1, tas.HCS_ID, tas.CLIENT_ID "
			+ "FROM (tbl_assessment_sheets  tas join tbl_client_basic tcb)"
		+ "WHERE ((tcb.CLIENTNAME LIKE #{username})OR (tas.ADDRESS1 LIKE #{address}) OR (tas.HCS_ID LIKE #{hcsid}))"
    + "AND ((tas.CLIENT_ID = tcb.UID) AND tas.CURRENT_USE = 1) GROUP BY tas.CLIENT_ID ")
  
	@ResultMap(value = "SelectUserResultMap")
	List<SelectClient> searchClientListByNameAddressID(@Param("username") String name, 
														@Param("address") String address, 
														@Param("hcsid") String hcsid);
	
	
	@Select("SELECT  tcb.UID, tcb.CLIENTNAME, tas.HCS_ID "
			+"FROM (tbl_assessment_sheets  tas join tbl_client_basic tcb) "
			+"WHERE (tas.CLIENT_ID = tcb.UID) AND tcb.UID = #{uid}")
	
	@ResultMap(value = "SelectUserNameMap")
	SelectClient findSelectClientPatientNameByUid(@Param("uid") int uid);
}